// pages/recruitEduback/recruitEduback.js
var app=getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:'',
    // workInfo: [],
    // educationInfo: [],
    // projectInfo: [],
    infoList:[],
    page:'',
    loadSuccess:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo')),
      page: options.page
    })
    
  },
  getWorkInfo: function () {
    var that = this;
    wx.request({
      url: app.globalData.httpApiCar + 'recruitWorkInfo/getByUserId', //仅为示例，并非真实的接口地址
      data: { userId: this.data.userInfo.id },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          loadSuccess: true
        })
        if (res.data.success) {
          if (res.data.data) {
            that.setData({
              infoList: res.data.data.pp
            })
          }
        }
      }
    })
  },
  getEducationInfo: function () {
    var that = this;
    wx.request({
      url: app.globalData.httpApiCar + 'recruitEducationInfo/getByUserId', //仅为示例，并非真实的接口地址
      data: { userId: this.data.userInfo.id },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          loadSuccess: true
        })
        if (res.data.success) {
          if (res.data.data) {
            that.setData({
              infoList: res.data.data.pp
            })
          }
        }
      }
    })
  },
  getProjectInfo: function () {
    var that = this;
    wx.request({
      url: app.globalData.httpApiCar + 'recruitProjectInfo/getByUserId', //仅为示例，并非真实的接口地址
      data: { userId: this.data.userInfo.id },
      success: function (res) {
        wx.hideLoading();
        that.setData({
          loadSuccess: true
        })
        if (res.data.success) {
          if (res.data.data) {
            that.setData({
              infoList: res.data.data.pp
            })
          }
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  addEduBack:function(){
    if (this.data.page == '1') {//教育背景
      wx.navigateTo({
        url: '/pages/recruitEdubackAdd/recruitEdubackAdd'
      })
    } else if (this.data.page == '2') {//工作/实习经历
      wx.navigateTo({
        url: '/pages/recruitWorkExpAdd/recruitWorkExpAdd'
      })
    } else {//项目经验
      wx.navigateTo({
        url: '/pages/recruitProjectExpAdd/recruitProjectExpAdd'
      })
    }
  },
  showDetail: function (e) {
    wx.setStorage({
      key: 'infoItem',
      data: e.currentTarget.dataset.item,
    })
    if (this.data.page == '1') {//教育背景
      wx.navigateTo({
        url: '/pages/recruitEdubackAdd/recruitEdubackAdd?isEdit=true'
      })
    } else if (this.data.page == '2') {//工作/实习经历
      wx.navigateTo({
        url: '/pages/recruitWorkExpAdd/recruitWorkExpAdd?isEdit=true'
      })
    } else {//项目经验
      wx.navigateTo({
        url: '/pages/recruitProjectExpAdd/recruitProjectExpAdd?isEdit=true'
      })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      loadSuccess: false
    })
    wx.showLoading({})
    var title = '';
    if (this.data.page == '1') {//教育背景
      this.getEducationInfo();
      title = '教育背景';
    } else if (this.data.page == '2') {//工作/实习经历
      this.getWorkInfo();
      title = '工作/实习经历';
    } else {//项目经验
      this.getProjectInfo();
      title = '项目经验';
    }
    wx.setNavigationBarTitle({
      title: title,
    })
    wx.removeStorage({
      key: 'infoItem'
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})